﻿Type=Class
Version=6
ModulesStructureVersion=1
B4A=true
@EndOfDesignText@

Sub Class_Globals
	Private ptelany As Panel
	Private iv_telanywhere As ImageView
	Dim nW As Int=70dip,nH As Int=70dip
	Private ol,ot,newl,newt As Int
	Private tmr As Timer
	Private tClick As Long=0
	Private nt As Int
End Sub

'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize(act As Activity)
	ptelany.Initialize("ptelany")
	tmr.Initialize("tmr",500)
	tmr.Enabled=True
	iv_telanywhere.Initialize("")
	ptelany.AddView(iv_telanywhere,0,0,nW,nH)
	iv_telanywhere.Bitmap=comm.bmpTelAnyWhere
	iv_telanywhere.Gravity=Gravity.FILL
	act.AddView(ptelany,90%x-nW,80%y,nW,nH)
	ptelany.BringToFront
	
	Log("ptelany added")
End Sub
Sub tmr_Tick
	If tmr.Interval=1500 Then
		tmr.Interval=1000
	Else
		tmr.Enabled=False
	End If
	ptelany.BringToFront
End Sub
Sub ptelany_Click
	Log("ptelany_click")
	Dim pi As Intent
	pi.Initialize(pi.ACTION_VIEW,"tel:"&comm.S_CLIENTPHONENUMBER)
	StartActivity(pi)
	
End Sub
Sub ptelany_Touch (Action As Int, X As Float, Y As Float)
	'Log("Action:"&Action&" x:"&X&" y:"&y)
	Select Action
	Case 0'按下
		tClick=DateTime.Now
		ol=ptelany.Left
		ot=ptelany.Top
	Case 2'移动
'		ptelany.Left=X-nWH/2
'		ptelany.Top=y-nWH/2

	Case 1'放开
'		ptelany.Left=(X+ol)
'		ptelany.top=(y+ot)
		newl=X+ol-nW/2
		newt=Y+ot-nH/2
		ptelany.SetLayoutAnimated(500,newl,newt,nW,nH)
		nt=DateTime.Now-tClick
'		Log("nt:"&nt&" x:"&Abs(newl-ol)&" Y:"&Abs(newt-ot))
		If nt<200 And (Abs(newl-ol)<20 Or Abs(newt-ot)<20) Then
			'如果按下到放开之间小于200ms钟则视为点击
			ptelany_Click
		End If
	End Select
End Sub